#ifndef MapScene_H
#define MapScene_H

#include <QGraphicsScene>
#include "MapItem.h"

QT_BEGIN_NAMESPACE
class QGraphicsSceneMouseEvent;
class QMenu;
class QPointF;
class QGraphicsLineItem;
class QFont;
class QGraphicsTextItem;
class QColor;
QT_END_NAMESPACE

class MapScene : public QGraphicsScene
{
    Q_OBJECT

public:
    enum Mode { InsertItem, InsertPath, InsertLine, InsertText, MoveItem };

    MapScene(QMenu *itemMenu, QObject *parent = 0);
    QFont font() const
        { return myFont; }
    QColor textColor() const
        { return myTextColor; }
    QColor itemColor() const
        { return myItemColor; }
    QColor lineColor() const
        { return myLineColor; }
    void setItemColor(const QColor &color);

public slots:
    void setMode(Mode mode);
    void setItemType(MapItem::DiagramType type);

signals:
	void startInserted(int id);
    void itemInserted(MapItem *item);
    void textInserted(QGraphicsTextItem *item);
    //void itemSelected(QGraphicsItem *item);

public:
	void addSpecificTile(QPoint position, MapItem::DiagramType diagramType);
	void clearAll();
	void hideAllPaths();
	void showPathWithId(int id);
	void setPathGroupId(int id);
	int startsCounter;
	void addPathCell(QPoint position, int id);

protected:
	bool event ( QEvent * event );
    void mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent);
    void mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent);
    void mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent);

private:
	int currentPathId;

    bool isItemChange(int type);
	void setMouseTargetPosition(QPointF scenePoint);
	void itemAtPosExisit(QPointF &pos, MapItem* itemNew);

	bool showMouseTarget;
	QGraphicsRectItem *mouseTarget;

    MapItem::DiagramType myItemType;
    QMenu *myItemMenu;
    Mode myMode;
    bool leftButtonDown;
    QPointF startPoint;
    QGraphicsLineItem *line;
    QFont myFont;
    QColor myTextColor;
    QColor myItemColor;
    QColor myLineColor;
};

#endif
